using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PocketAbapa
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();
			Layout();
		}

		void field_ScoreChanged(object sender, System.EventArgs e)
		{
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < field.Players.Count; i++)
			{
				int score = field.Players[i].Score;

				sb.Append("Player");
				sb.Append(i + 1);
				if (field.DidPlayerWin(i))
				{
					sb.Append(" wins");
				}
				sb.Append(": ");
				sb.Append(score);
				sb.Append("\n");
			}
			ScoreLabel.Text = sb.ToString();
		}

		void field_CurrentPlayerWon(object sender, System.EventArgs e)
		{
			MessageBox.Show("Player" + (field.Players.CurrentPlayerIndex + 1).ToString() + " wins!!!");
			Reset();
		}

		private void Reset_Click(object sender, EventArgs e)
		{
			Reset();
		}

		void Reset()
		{
			field.Reset();
			ScoreLabel.Text = "";
		}

		void MainForm_Resize(object sender, System.EventArgs e)
		{
			Layout();
		}

		void Layout()
		{
			this.field.Top = this.ScoreLabel.Bottom + 1;
			this.field.Width = this.ClientSize.Width;
		}

		void MenuAbout_Click(object sender, System.EventArgs e)
		{
			About dialog = new About();
			dialog.ShowDialog();
		}
	}
}